import requests
import random


def get_code():
    source = list('0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    for i in range(97, 123):
        source.append(chr(i))
    return ''.join(random.sample(source, 36))


jim = f'{get_code()[:6]}AAID{get_code()[:16]}AA{get_code()[:5]}'
print(jim)
url = f'https://api16-normal-useast1a.tiktokglobalshop.com/api/v2/trade/orders/get?main_order_id=576460906594142500&version=2&locale=zh-CN&language=zh-CN&oec_seller_id=7494083566701545386&aid=6556&app_name=i18n_ecom_shop&device_id=0&fp=verify_kv6cpa4t_mNghMfbj_sJjJ_4kpJ_9P1n_HNub8Bu1nUcK&device_platform=web&cookie_enabled=true&screen_width=1920&screen_height=1080&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F92.0.4515.107%20Safari%2F537.36&browser_online=true&timezone_name=Asia%2FShanghai&_signature=_02B4Z6wo00901{jim}'
headers = {
    'authority': 'api16-normal-useast1a.tiktokglobalshop.com',
    'method': 'POST',
    'path': '/api/v2/trade/orders/list?locale=zh-CN&language=zh-CN&oec_seller_id=7494083566701545386&aid=6556&app_name=i18n_ecom_shop&device_id=0&fp=verify_kv6cpa4t_mNghMfbj_sJjJ_4kpJ_9P1n_HNub8Bu1nUcK&device_platform=web&cookie_enabled=true&screen_width=1920&screen_height=1080&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F92.0.4515.107%20Safari%2F537.36&browser_online=true&timezone_name=Asia%2FShanghai&_signature=_02B4Z6wo00101wVvrwAAAIDDhW1VQ5nmYRcFb6uAAKA388',
    'scheme': 'https',
    'accept': '*/*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    'cache-control': 'no-cache',
    'content-length': '73',
    'content-type': 'application/json',
    'cookie': 'passport_csrf_token_default=26f18f275069f7c881b03ebe666a5f40; odin_tt=4f55b97acc888d9a15a01555d32390032515414b2e9defa6bfd5dc30a7ccd406f2ced26cb4a2c5fcdb43eb876f864653b11576382e2b6f123f55eba853190de4; sid_guard=b58fd05c13988d0860e9eac8b99c67cf%7C1635147717%7C259200%7CThu%2C+28-Oct-2021+07%3A41%3A57+GMT; uid_tt=41d3cc1c299f25a9cbc66e0b420158051caca83e173c73b961c48c1611910872; uid_tt_ss=41d3cc1c299f25a9cbc66e0b420158051caca83e173c73b961c48c1611910872; sid_tt=b58fd05c13988d0860e9eac8b99c67cf; sessionid=b58fd05c13988d0860e9eac8b99c67cf; sessionid_ss=b58fd05c13988d0860e9eac8b99c67cf; sid_ucp_v1=1.0.0-KGQzZDg4YWQ3YTg5ZmEyZmFhYjhjMTAzZGMyODlkN2M4MmFmZWQ2MzUKIAiCiICGrvWYsmEQxb_ZiwYYnDMgDDDT8pOLBjgBQOoHEAEaA3NnMSIgYjU4ZmQwNWMxMzk4OGQwODYwZTllYWM4Yjk5YzY3Y2Y; ssid_ucp_v1=1.0.0-KGQzZDg4YWQ3YTg5ZmEyZmFhYjhjMTAzZGMyODlkN2M4MmFmZWQ2MzUKIAiCiICGrvWYsmEQxb_ZiwYYnDMgDDDT8pOLBjgBQOoHEAEaA3NnMSIgYjU4ZmQwNWMxMzk4OGQwODYwZTllYWM4Yjk5YzY3Y2Y; store-idc=maliva; store-country-code=gb; passport_csrf_token=26f18f275069f7c881b03ebe666a5f40; msToken=HgLAL6mFg_81-OeX27IGDGOMlg0FeSWJMDFUDyuraIGq8wH4j5g2DEmZJlbk1c7EhAYxQHuGsNjfg9fC8Qan0yozEI8ApxvP2ChkEDdsColH; ttwid=1%7C5t8s3_hLea-zWsekqLF6LVnOF-DJzpLtFy3N6LkTsGg%7C1635152533%7C50f408267c777a69a6c83fe05ab50f9d1d732179c9aa495baccc8c178e9498b3; user_oec_info=0a53f8827b3107d593529ac89297178223bbcedd02192111a09bb2897b1b8e7ba486023bc1eac0f79473fc2998e105596cdefc2f87bd5d4c537138efdaba22cbfd04dcbfca4a758e3aee5eb3de09977cde9a83a3671a490a3c3af5935a7c4ced50642c377da8d0afb18877df427c787070f35ce11bd67c7623727d7d686275eb1e93d40a25f2f4085e75627481b2f8e29fcb5890b410eaadff0c1886d2f6f20d220104dddaf529',
    'origin': 'https://seller.tiktokglobalshop.com',
    'pragma': 'no-cache',
    'referer': 'https://seller.tiktokglobalshop.com/',
    'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
    'sec-ch-ua-mobile': '?0',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
}

data = {
    'locale': 'zh-CN',
    'language': 'zh-CN',
    'oec_seller_id': '7494083566701545386',
    'aid': '6556',
    'app_name': 'i18n_ecom_shop',
    'device_id': '0',
    'fp': 'verify_kv6cpa4t_mNghMfbj_sJjJ_4kpJ_9P1n_HNub8Bu1nUcK',
    'device_platform': 'web',
    'cookie_enabled': 'true',
    'screen_width': '1920',
    'screen_height': '1080',
    'browser_language': 'zh-CN',
    'browser_platform': 'Win32',
    'browser_name': 'Mozilla',
    'browser_version': '5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F92.0.4515.107%20Safari%2F537.36',
    'browser_online': 'true',
    'timezone_name': 'Asia%2FShanghai',
    '_signature': f'_02B4Z6wo00901{jim}',

}
for i in range(10):
    try:
        res = requests.get(url, headers=headers, params=data).content.decode()
        print(res)
    except ConnectionError as g:
        res = requests.get(url, headers=headers, params=data).content.decode()
        print(res)